from odoo import fields, models, api


class PeMerchant(models.Model):
    _name = 'pe.merchant'
    _inherit = ["mail.thread", "mail.activity.mixin"]
    _description = '商户'
    _sql_constraints = [('unique_internal_code','UNIQUE(internal_code)','内部编码需要唯一！')]

    name = fields.Char(string='主体名称',tracking=True)
    internal_code = fields.Char(string='内部编码',tracking=True)
    internal_name = fields.Char(string='内部名称',tracking=True)
    pe_merchant_account_id = fields.One2many(string='商户账户', comodel_name='pe.merchant.account', inverse_name='pe_merchant_id',tracking=True)
    exist_custom_software = fields.Boolean(string='存在定制软件',tracking=True)

    pe_merchant_shop_ids = fields.One2many(string='门店', comodel_name='pe.merchant.shop', inverse_name='pe_merchant_id',tracking=True)
    pe_industry_domain_ids = fields.Many2many(string='行业', comodel_name='pe.industry.domain', column1='pe_merchant_id',
                                              column2='pe_industry_domain_id',tracking=True)
    pe_partner_ids = fields.One2many(string='联系人', comodel_name='res.partner', inverse_name='pe_merchant_id',tracking=True)
    pe_marketing_status_id = fields.Many2one(string='运营状态', comodel_name='pe.marketing.status',tracking=True)
    pe_merchant_brand_ids = fields.Many2many(string='品牌', comodel_name='pe.device.brand', column1='pe_merchant_id',
                                             column2='pe_device_brand_id',tracking=True)
    remark = fields.Char(string='备注',tracking=True)



class PeMerchantAccount(models.Model):
    _name = 'pe.merchant.account'
    _description = '商户账户'

    pe_merchant_id = fields.Many2one(string='主表', comodel_name='pe.merchant')
    name = fields.Char(string='账户名称')
    pay_way = fields.Many2many(string='支付方式', comodel_name='pe.pay.way', column1='pe_merchant_account_id',
                               column2='pe_pay_way_id')
